# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.18.1)

# Declares and names the project.

project("openplaydemo")

# 1.定义so库和头文件所在目录
set(ffmpeg_lib_dir ${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI})
set(ffmpeg_head_dir ${CMAKE_SOURCE_DIR})


# 2.添加头文件目录
include_directories(${ffmpeg_head_dir}/include)

#3.添加ffmpeg相关的库
add_library(avutil
        SHARED
        IMPORTED )
set_target_properties(avutil
        PROPERTIES IMPORTED_LOCATION
        ${ffmpeg_lib_dir}/libavutil.so )
add_library(avresample
        SHARED
        IMPORTED )
set_target_properties(avresample
        PROPERTIES IMPORTED_LOCATION
        ${ffmpeg_lib_dir}/libavresample.so )

add_library(postproc
        SHARED
        IMPORTED )
set_target_properties(postproc
        PROPERTIES IMPORTED_LOCATION
        ${ffmpeg_lib_dir}/libpostproc.so )

add_library( swresample
        SHARED
        IMPORTED )
set_target_properties( swresample
        PROPERTIES IMPORTED_LOCATION
        ${ffmpeg_lib_dir}/libswresample.so )

add_library( avcodec
        SHARED
        IMPORTED )
set_target_properties( avcodec
        PROPERTIES IMPORTED_LOCATION
        ${ffmpeg_lib_dir}/libavcodec.so )

add_library( avfilter
        SHARED
        IMPORTED)
set_target_properties( avfilter
        PROPERTIES IMPORTED_LOCATION
        ${ffmpeg_lib_dir}/libavfilter.so )

add_library( swscale
        SHARED
        IMPORTED)
set_target_properties( swscale
        PROPERTIES IMPORTED_LOCATION
        ${ffmpeg_lib_dir}/libswscale.so )

add_library( avformat
        SHARED
        IMPORTED)
set_target_properties( avformat
        PROPERTIES IMPORTED_LOCATION
        ${ffmpeg_lib_dir}/libavformat.so )

#add_library( avdevice
#        SHARED
#        IMPORTED)
#set_target_properties( avdevice
#        PROPERTIES IMPORTED_LOCATION
#        ${ffmpeg_lib_dir}/libavdevice.so )

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

#配置目标so库的编译信息
add_library( # Sets the name of the library.
        openplaydemo

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        native-lib.cpp
        Player/Demux/IOpDemux.cpp
        Player/Demux/OpFFDemux.cpp
        Player/Demux/OpThread.cpp
        Player/Log/OpLog.cpp
        Player/Data/OpData.cpp
        Player/Observer/IOpObserver.cpp
        Player/Data/OpParameter.cpp
        Player/Decode/IOpDecode.cpp
        Player/Decode/OpFFDecode.cpp
        Player/Video/IOpVideoView.cpp
        Player/Video/OpVideoView.cpp
        Player/Video/OpEGL.cpp
        Player/Video/OpTexture.cpp
        Player/Shader/OpShader.cpp
        Player/Audio/IOpResample.cpp
        Player/Audio/OpFFResample.cpp
        Player/Audio/IOpAudioPlay.cpp
        Player/Audio/OpSLAudioPlay.cpp
        Player/IPlayer/IOpPlayer.cpp
        Player/IPlayer/IOpPlayerBuilder.cpp
        Player/IPlayer/OpPlayerBuilder.cpp
        Player/IPlayer/IOpPlayProxy.cpp
        )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
#查找代码中使用的系统库
find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

#指定编译目的库时，cmake要链接库
target_link_libraries( # Specifies the target library.
        openplaydemo
        #android端音频播放库
        OpenSLES
        #android端视频播放库
        EGL
        GLESv2
        #连接ndk原生库
        android
        # 连接ffmpeg相关的库
        avutil
        swresample
        avcodec
        avfilter
        swscale
        avformat
        avresample
        postproc
        #        avdevice

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})